<template>
  <el-dialog
    title="拉取自采血液数据"
    :visible.sync="dialogVisible"
    width="610px"
  >
    <el-form
      ref="form"
      :inline="true"
      :model="form"
      :rules="rules"
      size="small"
      @submit.native.prevent
    >
      <el-form-item class="pr8" prop="source">
        <el-select
          v-model="form.source"
          clearable
          filterable
          placeholder="血源"
          style="width: 140px"
        >
          <el-option
            v-for="(item, index) in bloodSources"
            :key="index"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item prop="created_at">
        <el-date-picker
          v-model="form.created_at"
          end-placeholder="结束时间"
          range-separator=" ~ "
          start-placeholder="录入开始时间"
          style="width: 320px"
          type="daterange"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" type="primary" @click="submit">
          拉取
        </el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
  import { mapGetters } from 'vuex'
  export default {
    data() {
      return {
        dialogVisible: false,
        form: {
          created_at: '',
          blood_source: '',
        },
        rules: {
          source: [{ required: true, message: '请选择血源', trigger: 'blur' }],
          created_at: [
            { required: true, message: '请选择日期时间', trigger: 'blur' },
          ],
        },
      }
    },
    computed: {
      ...mapGetters(['bloodSources']),
    },
    methods: {
      close() {
        this.form = {
          created_at: '',
          blood_source: '',
        }
        this.dialogVisible = false
      },
      show() {
        this.dialogVisible = true
      },
      submit() {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            this.dialogVisible = false
            this.$emit('submit', this.form)
          } else {
            return false
          }
        })
      },
    },
  }
</script>

<style lang="scss" scoped></style>
